package web.handle;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import ejb.entity.Notification;
import ejb.entity.Position;
import ejb.manager.NotificationManager;
import ejb.manager.PositionManager;

@ManagedBean
@ViewScoped
public class NotificationBean {
	@EJB
	private NotificationManager nm;
	@EJB
	private PositionManager pm;
	
	private int id;	
	private String message;
	private Position position;
	private int mintemp, maxtemp, minpressure, maxpressure, type;
	private List<Notification> notifications;

	public NotificationBean(){
		HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();		
		setId(Integer.parseInt(req.getParameter("id")));
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getMintemp() {
		return mintemp;
	}

	public void setMintemp(int mintemp) {
		this.mintemp = mintemp;
	}

	public int getMaxtemp() {
		return maxtemp;
	}

	public void setMaxtemp(int maxtemp) {
		this.maxtemp = maxtemp;
	}

	public int getMinpressure() {
		return minpressure;
	}

	public void setMinpressure(int minpressure) {
		this.minpressure = minpressure;
	}

	public int getMaxpressure() {
		return maxpressure;
	}

	public void setMaxpressure(int maxpressure) {
		this.maxpressure = maxpressure;
	}	
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Position getPosition() {
		this.position = pm.getPositionById(getId());
		return position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}
	
	public List<Notification> getNotifications() {
		this.setNotifications(nm.getPositionNotification(getId()));
		return notifications;
	}

	public void setNotifications(List<Notification> notifications) {
		this.notifications = notifications;
	}	
	
}

